package com.frxuexi.lib_base.utils

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.blankj.utilcode.util.SPUtils
import com.frxuexi.lib_base.http.Const

@Interceptor(priority = 1, name = "登录拦截")
class LoginInterceptor : IInterceptor {
    override fun init(context: Context?) {

    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        if (!SPUtils.getInstance().getString(Const.TOKEN, "").isNullOrEmpty() ||
            arrayOf("/app/LoginActivity","/app/RegisterActivity").contains(postcard?.path)
        ) {
            callback?.onContinue(postcard)
        } else {
            callback?.onInterrupt(Exception("登录拦截"))
            ArouterManager.nav(postcard?.context!!,"/app/LoginActivity")
        }
    }
}